package com.itheima.web.controller.cargo.job;



import com.itheima.dao.system.UserDao;
import com.itheima.domain.system.User;
import com.itheima.utils.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class UserJob {
    @Autowired
    private UserDao userDao;

    public void sendEmail() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd");
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        System.out.println("检测员工生日");
        List<User> userList = userDao.findAll("1");
        for (User user : userList) {
            String birthday = user.getBirthday();
            if (birthday.contains(format)){
                String email = user.getEmail();
                String userName = user.getUserName();
                 String title ="SaaS平台--生日快乐";
                 String content = "在过去的一年中，公司以稳定的步伐向前迈进。公司的发展离不开你和\n" +
                         "其它员工默默无闻的工作和努力。在你生日之际，公司代表全体员工向你衷心的说一句：生日快乐！愿你工作顺心，身体健康，万事如意。";
                MailUtil.sendMail(email,title,content);
                System.out.println("向"+userName+"发送生日祝福成功");
            }
        }

    }

}